// ConsoleApplication5.cpp : 定义控制台应用程序的入口点。
//
#include <stdio.h>
#include <WinSock2.h>
#include <mysql.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#pragma comment(lib,"ws2_32.lib")



void clearScreen() {
	system("cls");  // Windows
	// system("clear"); // Unix/Linux
}
char toUpperCase(char c) {
	return std::toupper(static_cast<unsigned char>(c));
}
using namespace std;
MYSQL mysql;
MYSQL_RES* res;//存储
MYSQL_ROW row;  //提取


const char DataBase_UserName[] = "root";    //数据库用户名username
const char DataBase_Password[] = "123456";   //数据库密码，填自己的密码
const char DataBase_Host[] = "localhost";  //数据库连接地址,写127.0.0.1也行
const char DataBase_Name[] = "data";  //数据库名称
unsigned int DataBase_Port = 3306;
void connect();
void UserLogin(SOCKET lpParam);
void UserEnroll(SOCKET lpParam);
void StudentOperation();
void TeacherOperation();
void MessageChange(string UserAccount, SOCKET lpParam);
void SearchMessage(SOCKET lpParam);
void CreateQue(SOCKET lpParam);
void PasswordChange(string UserAccount, SOCKET lpParam);
void sql_panduan(string sql, SOCKET clntSock);
void StudentDelete(SOCKET lpParam);
void Test(SOCKET lpParam);
void TestBegan(SOCKET lpParam);
void QueSearch(SOCKET lpParam);
void QueDelete(SOCKET lpParam);
string server(SOCKET lpParam);

enum choice
{
	login,
	enroll,
	logout
};
enum student_choice
{
	message_change = 1,
	text_parpare,
	student_logout

};
enum teacher_choice
{
	message_change_te = 1,
	search_message,
	s_m_d,
	create_que,
	search_que,
	account_logout


};
enum message
{
	studentID = 1,
	password
};
enum search_way
{
	all,
	student_id,
	account,
	role

};
void main()
{
	connect();

	int operation;
	WSADATA wsaData;
	WSAStartup(MAKEWORD(2, 2), &wsaData);

	//创建套接字
	SOCKET servSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);

	//绑定套接字
	struct sockaddr_in sockAddr;
	memset(&sockAddr, 0, sizeof(sockAddr));		//每个字节用0填充
	sockAddr.sin_family = PF_INET;				//使用ipv4
	sockAddr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
	sockAddr.sin_port = htons(8888);			//端口
	bind(servSock, (SOCKADDR*)&sockAddr, sizeof(SOCKADDR));

	//进入监听状态
	listen(servSock, 20);

	//接收客户端消息
	SOCKADDR clntAddr;
	int nSize = sizeof(SOCKADDR);
	SOCKET clntSock = accept(servSock, (SOCKADDR*)&clntAddr, &nSize);

	while (1) {
		printf("请选择操作（0.登录,1.注册,2.退出）:");
		char szBuffer[MAXBYTE] = { 0 };
		recv(clntSock, szBuffer, MAXBYTE, NULL);
		cout << "客户端：" << szBuffer << endl;


		if (strcmp(szBuffer, "登录操作") == 0)
		{
			UserLogin(clntSock);
		}
		else if (strcmp(szBuffer, "注册操作") == 0)
		{
			UserEnroll(clntSock);
		}
	}
	cout << "结束" << endl;


}//主函数






void connect()
{
	mysql_init(&mysql);
	if (mysql_real_connect(&mysql, DataBase_Host, DataBase_UserName, DataBase_Password, DataBase_Name, DataBase_Port, NULL, 0))
	{
		printf("连接成功....\n");
		mysql_query(&mysql, "use data;");

	}
}
void UserLogin(SOCKET lpParam)
{
	string UserAccount, UserPasswd;;
	cout << "请输入用户账号：";
	UserAccount = server(lpParam);
	cout << UserAccount << endl;
	cout << "请输入用户密码：";
	UserPasswd = server(lpParam);
	cout << UserPasswd << endl;
	string sql = "SELECT role FROM message where account = \"" + UserAccount + "\" and  password = \"" + UserPasswd + "\";";
	cout << "执行的sql语句为:" << sql << endl;
	const char* ss = sql.c_str();
	mysql_query(&mysql, ss);
	res = mysql_store_result(&mysql);

	if (row = mysql_fetch_row(res))
	{
		clearScreen();
		cout << "登录成功" << endl;
		const char* str = "登录成功";
		send(lpParam, str, strlen(str) + sizeof(char), NULL);
		string role = row[0];
		cout <<role << endl;
		string UserAccount_now = UserAccount;
		const char* ro = row[0];//身份验证
		send(lpParam, ro, strlen(ro) + sizeof(char), NULL);
		cout << ro << endl;
		if (role == "st")
		{
			cout << "欢迎同学" << endl;
			while (1)
			{

				StudentOperation();
				int student_operation;
				student_operation = stoi(server(lpParam));
				cout << student_operation << endl;
				switch (student_choice(student_operation))
				{

				case message_change:MessageChange(UserAccount_now, lpParam);
					break;
				case text_parpare:Test(lpParam);
					break;
				case student_logout:clearScreen(); return;
				default:printf("操作有误");
					break;
				}
			}
		}
		else
		{
			cout << "欢迎老师" << endl;


			while (1)
			{
				TeacherOperation();
				int teacher_operation;
				teacher_operation = stoi(server(lpParam));
				cout << teacher_operation << endl;
				switch (teacher_choice(teacher_operation))
				{
				case message_change_te:MessageChange(UserAccount_now, lpParam);
					break;
				case search_message:SearchMessage(lpParam);
					break;
				case s_m_d:StudentDelete(lpParam);
					break;
				case create_que:CreateQue(lpParam);
					break;
				case search_que:QueSearch(lpParam);
					break;
				case account_logout://clearScreen();
					return;
				default:cout << "操作有误,请重新输入" << endl;
					break;
				}
			}

		}


	}
	else
	{
		printf("账户不存在或账号密码错误,登录失败\n");
		const char* str = "账户不存在或账号密码错误,登录失败";
		send(lpParam, str, strlen(str) + sizeof(char), NULL);


	}


}
void UserEnroll(SOCKET lpParam)
{

	string cid, cname, cpwd, crol;
	cout << "请输入学号:";//将这些信息输出显示；
	cid = server(lpParam);//键盘输入信息；
	cout << cid << endl;
	cout << "请输入要创建的账号:";
	cname = server(lpParam);
	cout << cname << endl;
	cout << "请输入账号的密码:";
	cpwd = server(lpParam);
	cout << cpwd << endl;

	cout << "请输入你的身份(te/st):";
	crol = server(lpParam);
	cout << crol << endl;
	bool tem = false;

	if (crol == "te" || "st")
	{
		tem = true;
	}

	while (tem == false)
	{
		cout << "无此类身份,请再次输入(te/st):";
		crol = server(lpParam);
		cout << crol << endl;
		if (crol == "te" || "st")
		{
			break;
		}
	}
	string NewUser = "insert into message(StudentID ,account,password,role) values( \"" + cid + "\", \"" + cname + "\", \"" + cpwd + "\", \"" + crol + "\");";
	cout << NewUser << endl;
	const char* ss = NewUser.c_str();
	if (mysql_query(&mysql, ss))
	{
		printf("创建失败\n");
		const char* str = "创建失败";
		send(lpParam, str, strlen(str) + sizeof(char), NULL);
	}
	else
	{
		clearScreen();
		printf("创建成功\n");
		const char* str = "创建成功";
		send(lpParam, str, strlen(str) + sizeof(char), NULL);

	}
}
void StudentOperation()

{
	cout << "请输入以下数字来执行操作" << endl;
	cout << "1.修改信息" << endl;
	cout << "2.准备考试" << endl;
	cout << "3.退出" << endl;


}
void TeacherOperation()
{
	cout << "请输入以下数字来执行操作" << endl;
	cout << "1.修改信息" << endl;
	cout << "2.查询信息" << endl;
	cout << "3.删除学生信息" << endl;
	cout << "4.出题" << endl;
	cout << "5.查题" << endl;
	cout << "6.退出" << endl;
	cout << "请输入要执行的操作:";
}
void MessageChange(string UserAccount, SOCKET lpParam)
{
	cout << "请输入要修改的内容(1.学号,2.密码):";
	int choice;
	choice = stoi(server(lpParam));
	cout << choice << endl;
	string account, studentid;
	string sql;//sql语句
	switch (message(choice))
	{
	case studentID:cout << "请输入修改后的学号：";
		studentid = server(lpParam);
		sql = "update message  set StudentID  = \"" + studentid + "\"   where account = \"" + UserAccount + "\" ;";
		sql_panduan(sql, lpParam);
		break;
	case password:PasswordChange(UserAccount, lpParam);
		break;
	default:printf("操作有误,请重新输入");
		break;
	}


}
void SearchMessage(SOCKET lpParam)
{
	cout << "请输入查询方式(0.查询全部,1.学号查询,2.账户查询,3.角色查询):";
	string s, ID, name, Role;//查询方式
	int search_operation;//查询操作
	search_operation = stoi(server(lpParam));
	cout << search_operation << endl;
	switch (search_way(search_operation))
	{
	case all:s = "select* from message;";
		break;
	case student_id:
		cout << "请输入学号:";
		ID = server(lpParam);
		cout << ID << endl;
		s = "select * from message where StudentID ='" + ID + "';";
		break;
	case account:
		cout << "请输入账户:";
		name = server(lpParam);
		cout << name << endl;
		s = "select * from message where account ='" + name + "';";
		break;
	case role:
		cout << "请输入角色(st/te):";
		Role = server(lpParam);
		cout << Role << endl;
		s = "select * from message where role ='" + Role + "';";
		break;
	default:printf("操作有误");
		break;
	}
	cout << s << endl;





	const char* ss = s.c_str();
	mysql_query(&mysql, ss);
	res = mysql_store_result(&mysql);
	if (row = mysql_fetch_row(res))
	{
		const char* str = "登录成功";
		send(lpParam, str, strlen(str) + sizeof(char), NULL);
		printf("查询的用户存在\n");
		//printf("%s\n", ss);
		for (int i = 0; i < 9 + 15 + 9 + 9 + 9 + 25; i++)
		{
			printf("-");
		}
		printf("\n");
		do
		{

			const char* r0 = row[0];
			send(lpParam, r0, strlen(r0) + sizeof(char), NULL);

			const char* r1 = row[1];
			send(lpParam, r1, strlen(r1) + sizeof(char), NULL);

			const char* r2 = row[2];
			send(lpParam, r2, strlen(r2) + sizeof(char), NULL);

			const char* r3 = row[3];
			send(lpParam, r3, strlen(r3) + sizeof(char), NULL);

			const char* r4 = row[4];
			send(lpParam, r4, strlen(r4) + sizeof(char), NULL);

			cout << left << "      " << setw(9) << row[0] << "|     "
				<< setw(15) << row[1] << "|     "
				<< setw(9) << row[2] << "|     "
				<< setw(9) << row[3] << "|     "
				<< setw(9) << row[4] << endl;

			string sss = server(lpParam);
		} while (row = mysql_fetch_row(res));
		const char* r = "完成";
		send(lpParam, r, strlen(r) + sizeof(char), NULL);
		for (int i = 0; i < 9 + 15 + 9 + 9 + 9 + 25; i++)
		{
			printf("-");
		}printf("\n");
		cout << "本次查询结束" << endl;

	}
	else
	{
		const char* str1 = "无用户";
		send(lpParam, str1, strlen(str1) + sizeof(char), NULL);
		printf("用户不存在\n");
	}

}
void CreateQue(SOCKET lpParam)
{
	string qid, qname, qa, qb, qc, qd, qans, qscore;

	cout << "请输入题目：" << endl;

	qname = server(lpParam);
	cout << qname << endl;

	string s = "select * from question where qname = \"" + qname + "\";";
	const char* ss = s.c_str();
	mysql_query(&mysql, ss);
	printf("%s\n", ss);
	res = mysql_store_result(&mysql);
	if (row = mysql_fetch_row(res))
	{
		printf("添加的试题和表中的试题有重复的，创建项目不成功\n");
		const char* yanzheng = "失败";
		send(lpParam, yanzheng, strlen(yanzheng) + sizeof(char), NULL);
	}
	else
	{
		const char* yanzheng = "成功";
		send(lpParam, yanzheng, strlen(yanzheng) + sizeof(char), NULL);

		cout << "请输入题号：";
		qid = server(lpParam);
		cout << qid << endl;
		cout << "请输入选项A：";
		qa = server(lpParam);
		cout << qa << endl;
		cout << "请输入选项B：";
		qb = server(lpParam);
		cout << qb << endl;
		cout << "请输入选项C：";
		qc = server(lpParam);
		cout << qc << endl;
		cout << "请输入选项D：";
		qd = server(lpParam);
		cout << qd << endl;
		cout << "请输入标准答案：";
		qans = server(lpParam);
		cout << qans << endl;
		cout << "请输入分值：";
		qscore = server(lpParam);
		cout << qscore << endl;
		s = "insert into question( qid ,qname,choice_a,choice_b,choice_c,choice_d,choice_ans,qscore) values( \"" +
			qid + "\", \"" + qname + "\", \"" + qa + "\", \"" + qb + "\",\"" + qc + "\",\"" + qd + "\",\"" + qans + "\",\"" + qscore + "\");";
		ss = s.c_str();
		printf("%s\n", ss);


		if (mysql_query(&mysql, ss))
		{
			printf("添加试题失败(%s)", mysql_error(&mysql));
			const char* en = "添加试题失败";
			send(lpParam, en, strlen(en) + sizeof(char), NULL);


		}
		if (mysql_affected_rows(&mysql) > 0)
		{
			printf("试题添加成功\n");
			const char* en = "添加试题成功";
			send(lpParam, en, strlen(en) + sizeof(char), NULL);
		}


	}




}
void PasswordChange(string UserAccount, SOCKET lpParam)
{
	string UserPassword1, UserPassword2;
	cout << "请输入修改后的用户密码：";
	UserPassword1 = server(lpParam);
	cout << UserPassword1 << endl;
	cout << "请确认密码：";
	UserPassword2 = server(lpParam);
	cout << UserPassword2 << endl;
	while (UserPassword2 != UserPassword1)
	{
		cout << "两次密码输入不相同，请重新输入";
		cout << "请输入修改后的用户密码：" << endl;
		UserPassword1 = server(lpParam);
		cout << UserPassword1 << endl;
		cout << "请确认密码：" << endl;
		UserPassword1 = server(lpParam);
		cout << UserPassword2 << endl;
	}
	string sql = "update message  set password  = \"" + UserPassword1 + "\"   where account = \"" + UserAccount + "\" ;";
	cout << "执行的sql语句为:" << sql << endl;
	//const char* ss = sql.c_str();
	sql_panduan(sql, lpParam);


}
void StudentDelete(SOCKET lpParam)
{
	cout << "请输入删除方式(1.学号查询,2.账户查询,3.取消删除):";
	string s, ID, name, s1;//查询方式
	int search_operation;//查询操作
	search_operation = stoi(server(lpParam));
	cout << search_operation << endl;
	switch (search_way(search_operation))
	{
	case student_id:
		cout << "请输入学号:";
		ID = server(lpParam);
		cout << ID << endl;
		s = "DELETE FROM message WHERE   StudentID  ='" + ID + "' and role='st' ;";
		s1 = "select * from message where StudentID ='" + ID + "' and role='st' ;";
		break;
	case account:
		cout << "请输入账户:";
		name = server(lpParam);
		cout << name << endl;
		s = "DELETE FROM message WHERE account='" + name + "' and role='st' ;";
		s1 = "select * from message where account ='" + name + "' and role='st' ;";
		break;
	case 3:return;
	default:printf("操作有误");
		break;
	}
	const char* ss = s1.c_str();
	mysql_query(&mysql, ss);
	res = mysql_store_result(&mysql);
	if (row = mysql_fetch_row(res))
	{
		const char* str = "登录成功";
		send(lpParam, str, strlen(str) + sizeof(char), NULL);
		printf("查询的用户存在\n");
		printf("%s\n", ss);
		for (int i = 0; i < 9 + 15 + 9 + 9 + 9 + 25; i++)
		{
			printf("-");
		}
		printf("\n");
		do
		{

			const char* r0 = row[0];
			send(lpParam, r0, strlen(r0) + sizeof(char), NULL);
			const char* r1 = row[1];
			send(lpParam, r1, strlen(r1) + sizeof(char), NULL);
			const char* r2 = row[2];
			send(lpParam, r2, strlen(r2) + sizeof(char), NULL);
			const char* r3 = row[3];
			send(lpParam, r3, strlen(r3) + sizeof(char), NULL);
			const char* r4 = row[4];
			send(lpParam, r4, strlen(r4) + sizeof(char), NULL);
			cout << left << "      " << setw(9) << row[0] << "|     "
				<< setw(15) << row[1] << "|     "
				<< setw(9) << row[2] << "|     "
				<< setw(9) << row[3] << "|     "
				<< setw(9) << row[4] << endl;


		} while (row = mysql_fetch_row(res));
		const char* r = "完成";
		send(lpParam, r, strlen(r) + sizeof(char), NULL);




		for (int i = 0; i < 9 + 15 + 9 + 9 + 9 + 25; i++)
		{
			printf("-");
		}printf("\n");


		string sure;
		cout << role << endl;
		cout << "确认删除(Y/N)?:";
		ss = s.c_str();
		sure = server(lpParam);
		cout << sure << endl;
		cout << s << endl;
		if (sure == "Y")
		{


			if (!mysql_query(&mysql, ss))
			{
				cout << "删除成功" << endl;
			}
			else
			{
				cout << "出现问题,删除失败" << endl;
			}
		}

		else if (sure == "N")

		{
			cout << "删除取消" << endl;
		}
		else
		{
			cout << "删除失败" << endl;
		}
	}
	else
	{
		cout << "查无此人" << endl;
	}

}
void Test(SOCKET lpParam)
{
	string sure;
	cout << "Are you ready(Y/N)：";
	sure = server(lpParam);
	cout << sure << endl;
	if (sure == "Y")
	{

		TestBegan(lpParam);
	}
	else
	{
		cout << "考试已取消" << endl;
		return;
	}


}
void TestBegan(SOCKET lpParam)
{
	printf("开始考试");
	const int QuNumber = 3;
	int Score = 0, Number = 0;
	string sql = "SELECT * FROM question ORDER BY RAND() LIMIT 3;";
	mysql_query(&mysql, sql.c_str());
	res = mysql_store_result(&mysql);
	int i = 1;
	char stu_choice;
	char StuChoice[QuNumber];
	char AnswerChoice[QuNumber];
	int score[QuNumber];
	while (row = mysql_fetch_row(res))
	{


		const char* r1 = row[1];
		send(lpParam, r1, strlen(r1) + sizeof(char), NULL);
		const char* r2 = row[2];
		send(lpParam, r2, strlen(r2) + sizeof(char), NULL);
		const char* r3 = row[3];
		send(lpParam, r3, strlen(r3) + sizeof(char), NULL);
		const char* r4 = row[4];
		send(lpParam, r4, strlen(r4) + sizeof(char), NULL);
		const char* r5 = row[5];
		send(lpParam, r5, strlen(r5) + sizeof(char), NULL);
		cout << left << i << ". "
			<< setw(25) << row[1] << "A:"
			<< setw(9) << row[2] << "B:"
			<< setw(9) << row[3] << "C:"
			<< setw(9) << row[4] << "D:"
			<< setw(9) << row[5] << endl << "请选择(A,B,C,D):";
		//int answer= row[6]
		stu_choice = server(lpParam)[0];
		cout << stu_choice << endl;

		StuChoice[i - 1] = toUpperCase(stu_choice);

		const char* r6 = row[6];
		send(lpParam, r6, strlen(r6) + sizeof(char), NULL);
		AnswerChoice[i - 1] = row[6][0];

		const char* r7 = row[7];
		send(lpParam, r7, strlen(r7) + sizeof(char), NULL);
		score[i - 1] = stoi(row[7]);
		i++;
	}


	const char* r = "完成";
	send(lpParam, r, strlen(r) + sizeof(char), NULL);
	for (int k = 0; k < i - 1; k++)
	{

		cout << StuChoice[k] << " " << AnswerChoice[k] << endl;
		if (StuChoice[k] == AnswerChoice[k])
		{
			Score += score[k];
			Number++;
		}

	}

	printf("学生共答对了%d题目,得分为%d\n", Number, Score);
	if (Score < 60)
	{
		printf("继续努力\n");
		printf("\n");
	}
	else if (Score == 100)
	{
		cout << "牛逼" << endl;
		printf("\n");
	}
	{

	}

}
void QueSearch(SOCKET lpParam)
{
	string sql = "SELECT * FROM question ;";
	mysql_query(&mysql, sql.c_str());
	//获取结果集
	res = mysql_store_result(&mysql);

	for (int i = 0; i < 9 + 15 + 25 + 25 + 25 + 25 + 25; i++)
	{
		printf("-");
	}printf("\n");
	//显示数据
	//给ROW赋值，判断ROW是否为空，不为空就打印数据。
	while (row = mysql_fetch_row(res))
	{
		const char* r0 = row[0];
		send(lpParam, r0, strlen(r0) + sizeof(char), NULL);
		const char* r1 = row[1];
		send(lpParam, r1, strlen(r1) + sizeof(char), NULL);
		const char* r2 = row[2];
		send(lpParam, r2, strlen(r2) + sizeof(char), NULL);
		const char* r3 = row[3];
		send(lpParam, r3, strlen(r3) + sizeof(char), NULL);
		const char* r4 = row[4];
		send(lpParam, r4, strlen(r4) + sizeof(char), NULL);
		const char* r5 = row[5];
		send(lpParam, r5, strlen(r5) + sizeof(char), NULL);
		const char* r6 = row[6];
		send(lpParam, r6, strlen(r6) + sizeof(char), NULL);
		const char* r7 = row[7];
		send(lpParam, r7, strlen(r7) + sizeof(char), NULL);
		cout << left << "      " << setw(9) << row[0] << "|     "
			<< setw(35) << row[1] << "|     "
			<< setw(9) << row[2] << "|     "
			<< setw(9) << row[3] << "|     "
			<< setw(9) << row[4] << "|     "
			<< setw(9) << row[5] << "|     "
			<< setw(9) << row[6] << "|     "
			<< setw(9) << row[7] << endl;
		string sss = server(lpParam);
	}
	const char* r = "完成";
	send(lpParam, r, strlen(r) + sizeof(char), NULL);
	for (int i = 0; i < 9 + 15 + 25 + 25 + 25 + 25 + 25; i++)
	{
		printf("-");
	}printf("\n");

	cout << "请选择操作(1.删除/2.取消):";
	int operation;
	operation = stoi(server(lpParam));
	cout << operation << endl;
	switch (operation)
	{
	case 1:QueDelete(lpParam);
		break;
	case 2:return;
		break;
	default:cout << "操作错误" << endl;
		break;
	}



}
void QueDelete(SOCKET lpParam)
{
	cout << "请输入要删除的题目的序号:";
	string id;
	id = server(lpParam);
	cout << id << endl;
	string sql = "select * from question where qid  = " + id + ";";
	string sql1 = "DELETE FROM question WHERE  qid  = " + id + ";";
	cout << sql << endl;
	const char* ss = sql.c_str();
	mysql_query(&mysql, ss);
	res = mysql_store_result(&mysql);
	if (row = mysql_fetch_row(res))
	{
		const char* R = "存在";
		send(lpParam, R, strlen(R) + sizeof(char), NULL);
		printf("查询的问题存在\n");
		for (int i = 0; i < 9 + 15 + 25 + 25 + 25 + 25 + 25; i++)
		{
			printf("-");
		}printf("\n");
		//显示数据
		//给ROW赋值，判断ROW是否为空，不为空就打印数据。
		do
		{
			const char* r0 = row[0];
			send(lpParam, r0, strlen(r0) + sizeof(char), NULL);
			const char* r1 = row[1];
			send(lpParam, r1, strlen(r1) + sizeof(char), NULL);
			const char* r2 = row[2];
			send(lpParam, r2, strlen(r2) + sizeof(char), NULL);
			const char* r3 = row[3];
			send(lpParam, r3, strlen(r3) + sizeof(char), NULL);
			const char* r4 = row[4];
			send(lpParam, r4, strlen(r4) + sizeof(char), NULL);
			const char* r5 = row[5];
			send(lpParam, r5, strlen(r5) + sizeof(char), NULL);
			const char* r6 = row[6];
			send(lpParam, r6, strlen(r6) + sizeof(char), NULL);
			const char* r7 = row[7];
			send(lpParam, r7, strlen(r7) + sizeof(char), NULL);
			cout << left << "      " << setw(9) << row[0] << "|     "
				<< setw(35) << row[1] << "|     "
				<< setw(9) << row[2] << "|     "
				<< setw(9) << row[3] << "|     "
				<< setw(9) << row[4] << "|     "
				<< setw(9) << row[5] << "|     "
				<< setw(9) << row[6] << "|     "
				<< setw(9) << row[7] << endl;
		} while (row = mysql_fetch_row(res));
		const char* r = "完成";
		send(lpParam, r, strlen(r) + sizeof(char), NULL);
		for (int i = 0; i < 9 + 15 + 25 + 25 + 25 + 25 + 25; i++)
		{
			printf("-");
		}printf("\n");
		string sure;
		cout << "确认删除(Y/N)?:";
		ss = sql1.c_str();
		sure = server(lpParam);
		cout << sure << endl;
		if (sure == "Y")
		{
		
			mysql_query(&mysql, ss);
			cout << "删除成功" << endl;
			const char* r = "成功";
			send(lpParam, r, strlen(r) + sizeof(char), NULL);

		}

		else if (sure == "N")

		{
			cout << "删除取消" << endl;
		}

	}
	else
	{
		cout << "查无此问题" << endl;
	}





}
void sql_panduan(string sql, SOCKET clntSock)
{

	const char* ss = sql.c_str();

	if (!mysql_query(&mysql, ss))
	{
		cout << "修改成功" << endl;
		const char* str = "修改成功";
		send(clntSock, str, strlen(str) + sizeof(char), NULL);

	}
	else
	{
		cout << "修改失败" << endl;
		const char* str = "修改失败";
		send(clntSock, str, strlen(str) + sizeof(char), NULL);
	}
}
string server(SOCKET lpParam)
{

	char szBuffer[MAXBYTE] = { 0 };
	recv(lpParam, szBuffer, MAXBYTE, 0);
	return szBuffer;
}


